import logging
from websocket_server import WebsocketServer


class Server(object):
    _instance = None
    _server = None

    def __new__(cls, *args, **kw):
        if cls._instance is None:
            cls._instance = object.__new__(cls, *args, **kw)
        return cls._instance

    def __init__(self):
        pass

    def send(self, msg):
        if self._server is not None:
            self._server.send_message_to_all(msg)

    def add_server(self, server):
        self._instance._server = server
        print(self._instance._server)


if __name__ == "__main__":
    s = Server()
    # print(id(s))
    server = WebsocketServer(host='127.0.0.1', port=13254, loglevel=logging.INFO)
    s.add_server(server)
    server.run_forever()